//
//  luoerTabbarController.swift
//  WeiBoStudy
///Users/liuwenping/isoWeiBo/WeiBoStudy/WeiBoStudy
//  Created by luoerliu on 16/5/11.
//  Copyright © 2016年 刘文平. All rights reserved.
//

import UIKit

class luoerTabbarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        定义闭包
        let compseCallback = { () -> () in
               print(" 弹出控制器")
        }
       let mainTabBar  = luoerMainTabBar()
        mainTabBar.composeCallback =  compseCallback
        setValue(mainTabBar, forKey: "tabBar")
        let homeVC = luoerHomeViewController()
        self.addChildViewController(homeVC, title: "首页", image: "tabbar_home")
        let profileVC = luoerProfileiewController()
        self.addChildViewController(profileVC, title: "我的", image: "tabbar_profile")
        let discover = luoerDiscoveryViewController()
        self.addChildViewController(discover, title: "发现", image: "tabbar_discover")
        let message = luoerMessageViewController()
        self.addChildViewController(message, title: "消息", image: "tabbar_message_center")
    }
//    为tabbarControll添加子控制器方法
    private func addChildViewController(controller:UIViewController,title:String,image:String)
    {
//        设置标题
        controller.title = title
//        设置tabbar的图片
        controller.tabBarItem.image = UIImage(named: image)
//        设置高亮图片、
        controller.tabBarItem.selectedImage = UIImage(named:image + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        设置文字高亮的颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
//        包装导航控制器
        self.addChildViewController(UINavigationController(rootViewController: controller))
        
    }
}
